package com.example.demo.dto;

import com.example.demo.model.UserRole;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
@ApiModel("用户注册请求体")
@Schema(name = "RegisterDTO", description = "用户注册数据传输对象")
public class RegisterDTO {

    @NotBlank(message = "用户名不能为空")
    @Size(min = 4, max = 20, message = "用户名长度需为4-20位")
    @ApiModelProperty(value = "用户名", required = true, example = "john_doe")
    @Schema(description = "用户名", example = "john_doe", minLength = 4, maxLength = 20)
    private String username;

    @NotBlank(message = "密码不能为空")
    @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{8,}$",
            message = "密码需包含字母和数字且至少8位")
    @ApiModelProperty(value = "密码", required = true, example = "Password123")
    @Schema(description = "密码", example = "Password123", format = "password")
    private String password;

    @ApiModelProperty(value = "用户角色", example = "USER", hidden = true) // 隐藏角色字段，避免前端传递
    @Schema(description = "用户角色（默认USER）", example = "USER", defaultValue = "USER")
    private UserRole role = UserRole.USER; // 设置默认角色
}
